package com.cloud.config.mybatis.base.dto;

import com.cloud.common.constant.CommonConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotNull;

/**
 * 分页DTO
 *
 * @author wangjian
 * @version 1.0.0
 * @create 2020年10月26日 11:16
 * @since JDK 1.8
 * Life is so short,do something to make yourself happy,such as coding
 */
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel("分页查询参数对象")
public class PageDTO extends CommonDTO {

    @ApiModelProperty(value = "页码,默认为1", example = "1")
    @NotNull(message = "页码不能为空")
    private Long page = CommonConstant.DEFAULT_PAGE;

    @ApiModelProperty(value = "行数,默认为10", example = "10")
    @NotNull(message = "行数不能为空")
    private Long limit = CommonConstant.DEFAULT_LIMIT;

    public void setPage(long page) {
        if (page <= 0) {
            this.page = CommonConstant.DEFAULT_PAGE;
        } else {
            this.page = page;
        }
    }

    public void setLimit(long limit) {
        if (limit <= 0) {
            this.limit = CommonConstant.DEFAULT_LIMIT;
        } else if (this.limit >= CommonConstant.MAX_LIMIT) {
            this.limit = CommonConstant.MAX_LIMIT;
        } else {
            this.limit = limit;
        }
    }

}
